package com.aaronprj.common.utils.mbooks;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.aaronprj.common.entities.SgmenuEntityManager;
import com.aaronprj.common.entities.mbooks.BookItem;
import com.aaronprj.common.entities.mbooks.User;
import com.aaronprj.common.enums.UserRole;
import com.aaronprj.common.enums.mbooks.Course;
import com.aaronprj.common.enums.mbooks.ItemCategory;

public class SystemInitialHelper {

	public static void initial(){
		createUsers();

		
	}
	
	public static void createUsers(){
		User tmpuser = new User();
		//user.setId(1);
		tmpuser.setUserName("admin");
		tmpuser.setPassword("password");
		tmpuser.setEmail("admin@sgmenu.com");
		tmpuser.setRole(UserRole.Administrator);
		

		User cuser1 = new User();
		//user.setId(1);
		cuser1.setUserName("user1");
		cuser1.setPassword("password");
		cuser1.setEmail("user1@sgmenu.com");
		cuser1.setRole(UserRole.Costumer);
		
		User cuser2 = new User();
		//user.setId(1);
		cuser2.setUserName("user2");
		cuser2.setPassword("password");
		cuser2.setEmail("user2@sgmenu.com");
		cuser2.setRole(UserRole.Costumer);
		
		SgmenuEntityManager.save(new Object[]{tmpuser,cuser1,cuser2});
	}

	
	public static void createBookItems(){
		List<Object> ftbs = new ArrayList<Object>();
		List<String> paths = new ArrayList<String>();
		paths.add("25709163.jpg");
		paths.add("34880511.jpg");
		paths.add("35810927.jpg");
		paths.add("50809212.jpg");
		paths.add("58297154.jpg");
		paths.add("71005426.jpg");
		paths.add("76493939.jpg");
		paths.add("77193926.jpg");
		
		int i = 0;
		
    	for(Course c:Course.getEntityList()){
    		if(i < paths.size()){
		    	BookItem fi = new BookItem();
		    	fi.setCategory(c.getCategory());
		    	fi.setName(c.getDisplayName() + " item "+i);
		    	fi.setDiscription(c.getDisplayName() + " item "+i + " discription");
		    	fi.setAuthor("author "+i);
		    	fi.setIsdn("ISDN"+i+(new Date()).getTime());
		    	fi.setCourse(c);
		    	fi.setPrice(3.5*c.getOrder()-(i/10));

		    	fi.setImgpath("pix/"+paths.get(i));
		    	ftbs.add(fi);

		    	i++;
    		}else{
    			break;
    		}
		}
		
    	SgmenuEntityManager.save(ftbs.toArray());
		
	}
	
	
}
